package com.jm.offer.easy;

import com.jm.offer.TreeNode;

/**
 * @Description https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/
 * @date 2022/4/28 8:42
 */
public class _55_II平衡二叉树 {


    public boolean isBalanced(TreeNode root) {
        if (root == null) {
            return true;
        }
        return Math.abs(depth(root.left) - depth(root.right)) <= 1 && isBalanced(root.left) && isBalanced(root.right);
    }

    private int depth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(depth(root.left), depth(root.right)) + 1;
    }
}
